<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 13] 13.2 Character Escape Sequences</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:00:50 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch13_01.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 13<br>Java Syntax</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch13_03.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-13-SECT-2">13.2 Character Escape Sequences</A></h2>

<P CLASS=para>
<A NAME="CH13.CHARACTER.ES1"></A><A NAME="CH13.ESCAPE.SEQUE1"></A>Java uses the escape sequences listed in <A HREF="ch13_02.htm#JNUT2-CH-13-TAB-2">Table 13.2</A>
to represent certain special character values.  These escape
sequences may appear in any Java <tt CLASS=literal>char</tt> or
<tt CLASS=literal>String</tt> literal.

<P>
<DIV CLASS=table>
<TABLE BORDER>
<CAPTION><A CLASS="TITLE" NAME="JNUT2-CH-13-TAB-2">Table 13.2: Java Escape Characters</A></CAPTION>
<TR CLASS=row>
<TH ALIGN="left">Escape Sequence</TH>
<TH ALIGN="left">Character Value</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\b</TD>
<TD ALIGN="left">Backspace</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\t</TD>
<TD ALIGN="left">Horizontal tab</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\n</TD>
<TD ALIGN="left">Newline</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\f</TD>
<TD ALIGN="left">Form feed</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\r</TD>
<TD ALIGN="left">Carriage return</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\"</TD>
<TD ALIGN="left">Double quote</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\'</TD>
<TD ALIGN="left">Single quote</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\\</TD>
<TD ALIGN="left">Backslash</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\<tt CLASS=literal>xxx</tt></TD>
<TD ALIGN="left">

<P CLASS=para>
The character corresponding to the octal value <tt CLASS=literal>xxx</tt>,
where <tt CLASS=literal>xxx</tt> is between 000 and 0377.</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">\u<tt CLASS=literal>xxxx</tt></TD>
<TD ALIGN="left">

<P CLASS=para>
The Unicode character with encoding <tt CLASS=literal>xxxx</tt>, where
<tt CLASS=literal>xxxx</tt> is one to four hexidecimal digits.  Unicode
escapes are distinct from the other escape types listed
here; they are described below in more detail.</TD>
</TR>
</TABLE>
<P>
</DIV>
<P CLASS=para>
Java characters, strings, and identifiers (e.g., field,
method, and class names) are composed of 16-bit Unicode
characters.  The Unicode <tt CLASS=literal>\u</tt> escape sequence may be
used anywhere in a Java program (not only in <tt CLASS=literal>char</tt>
and <tt CLASS=literal>String</tt> literals) to represent a Unicode character.

<P CLASS=para>
Unicode <tt CLASS=literal>\u</tt> escape sequences are processed before
the other escape sequences described in
<A HREF="ch13_02.htm#JNUT2-CH-13-SECT-2">Character Escape Sequences</A>,
and thus the two types of escape sequences can have very
different semantics.  A Unicode escape is simply an
alternative way to represent a character which may not be
displayable on non-Unicode systems.  The character
escapes, however, can represent special characters in a way
that prevents the usual interpretation of those characters
by the compiler.

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch13_01.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch13_03.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Primitive Data Types</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Operators</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
